// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.Resources;
using System.Web.Script;
using AjaxControlToolkit;
using System.Drawing;

[assembly: System.Web.UI.WebResource("GridControl.Spinner.SpinnerExtenderBehavior.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("GridControl.Spinner.Spinner.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("GridControl.Spinner.spinner.gif", "img/gif")]
[assembly: System.Web.UI.WebResource("GridControl.Spinner.spinner-split.gif", "img/gif")]
[assembly: System.Web.UI.WebResource("GridControl.Spinner.spinner.css", "text/css", PerformSubstitution = true)]

namespace GridControl
{ 
    /// <summary>
    /// Class to extend a TextBox into a Spinner 
    /// </summary>
    [ClientScriptResource("GridControl.SpinnerExtenderBehavior", "GridControl.Spinner.SpinnerExtenderBehavior.js")]
    [RequiredScript(typeof(YUI), 1)]
    [RequiredScript(typeof(ext_yui_adapter), 2)]
    [RequiredScript(typeof(YUI_ext), 3)]
    [RequiredScript(typeof(SpinnerJs), 4)]
    [TargetControlType(typeof(TextBox))]
    public class SpinnerExtender : ExtenderControlBase
    {   
        /// <summary>
        ///  Lower bound value for the spinner field
        /// </summary>
        [ExtenderControlProperty]
        public string minValue
        {
            get
            {
                return GetPropertyValue<string>("minValue", "0");
            }
            set
            {
                SetPropertyValue<string>("minValue", value);
            }
        }
        /// <summary>
        /// The upper bound value for the spinner control
        /// </summary>
        [ExtenderControlProperty]
        public string maxValue
        {
            get
            {
                return GetPropertyValue<string>("maxValue", int.MaxValue.ToString());
            }
            set
            {
                SetPropertyValue<string>("maxValue", value);
            }
        }
        /// <summary>
        /// The amount of the increment
        /// </summary>
        [ExtenderControlProperty]
        public int incrementValue
        {
            get
            {
                return GetPropertyValue<int>("incrementValue", 1);
            }
            set
            {
                SetPropertyValue<int>("incrementValue", value);
            }

        }
        /// <summary>
        /// The increment applied when the shift key is pressed
        /// </summary>
        [ExtenderControlProperty]
        public int alternateIncrementValue
        {
            get
            {
                return GetPropertyValue<int>("alternateIncrementValue", 5);
            }
            set
            {
                SetPropertyValue<int>("alternateIncrementValue", value);
            }

        }
        /// <summary>
        /// Raises the pre render event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string resource = Page.ClientScript.GetWebResourceUrl(GetType(), "GridControl.yui-ext.css");
            string csslink = "<link href='" + resource + "' rel='stylesheet' type='text/css' />";
            Page.Header.Controls.Add(new LiteralControl(csslink));

            resource = Page.ClientScript.GetWebResourceUrl(GetType(), "GridControl.Spinner.spinner.css");
            csslink = "<link href='" + resource + "' rel='stylesheet' type='text/css' />";
            Page.Header.Controls.Add(new LiteralControl(csslink));

          
        }
    }
}